package com.lun.easy;

public class DetectCapital {
	
    public boolean detectCapitalUse(String word) {
        int capitalCount = 0, notCapitalCount = 0;
        boolean firstLetterCapital = Character.isUpperCase(word.charAt(0));
        
        for(int i = 0; i < word.length(); i++) {
        	if(Character.isUpperCase(word.charAt(i))) {
        		capitalCount++;
        	}else {
        		notCapitalCount++;
        	}
        }
        
        return firstLetterCapital && notCapitalCount == word.length() - 1 //
        		|| notCapitalCount == word.length()//
        		|| capitalCount == word.length(); 
    }
    
    public boolean detectCapitalUse2(String word) {
        return word.matches("[A-Z]*|[A-Z]?[a-z]*");
    }
    
}
